BatchToSpace
将输入张量在批维度上分块并重新分布到空间维度,同时按照 crops 对输出空间范围进行裁剪。
\[\begin{split}\begin{aligned} N_{\text{out}} &= \frac{N}{b_h \times b_w}, \\ H_{\text{out}} &= b_h \times H - c_{\text{top}} - c_{\text{bottom}}, \\ W_{\text{out}} &= b_w \times W - c_{\text{left}} - c_{\text{right}}, \\ ext{output}[n, h, w, c] &= \text{input}[n', h', w', c] \end{aligned}\end{split}\]其中 \(N, H, W, C\) 分别表示输入的 batch、高度、宽度和通道数;\(b_h, b_w\) 为
block_size;\(c_{*}\) 来源于crops;\(n', h', w'\) 由BatchToSpace映射关系确定。
- 输入:
input - 输入数据地址。
input_shape - 输入形状,格式为
[batch, height, width, channel]。block_size - 分块因子,格式为
[block_h, block_w]。crops - 裁剪参数,格式为
[top, bottom, left, right]。core_mask(int, 可选) - 核掩码(仅适用于共享存储版本)。
- 输出:
output - 输出数据地址。
- 支持平台:
FT78NEMT7004备注
FT78NE 支持 fp32、fp64、cplx64、cplx128、int16、int8、int32 数据类型。
MT7004 支持 fp32、fp16、cplx64、int16、int32 数据类型。
共享存储版本:
-
void i8_batchtospace_s(int8_t *input, int8_t *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void i16_batchtospace_s(int16_t *input, int16_t *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void i32_batchtospace_s(int32_t *input, int32_t *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void hp_batchtospace_s(half *input, half *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void fp_batchtospace_s(float *input, float *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void dp_batchtospace_s(double *input, double *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void c64_batchtospace_s(float *input, float *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
-
void c128_batchtospace_s(double *input, double *output, const int *input_shape, const int *block_size, const int *crops, int data_size, int core_mask)
C 调用示例:
1// 多核(共享存储)示例 2#include <stdio.h> 3 4int main(int argc, char *argv[]) { 5 float *input = (float *)0xA0000000; // 输入在 DDR 空间 6 float *output = (float *)0xB0000000; 7 int input_shape[4] = {400, 2, 2, 3}; 8 int block_size[2] = {2, 2}; 9 int crops[4] = {0, 0, 0, 0}; 10 int core_mask = 0xff; 11 fp_batchtospace_s(input, output, input_shape, block_size, crops, sizeof(float), core_mask); 12 return 0; 13}
私有存储版本:
-
void i8_batchtospace_p(int8_t *input, int8_t *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void i16_batchtospace_p(int16_t *input, int16_t *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void i32_batchtospace_p(int32_t *input, int32_t *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void hp_batchtospace_p(half *input, half *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void fp_batchtospace_p(float *input, float *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void dp_batchtospace_p(double *input, double *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void c64_batchtospace_p(float *input, float *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
-
void c128_batchtospace_p(double *input, double *output, const int *input_shape, const int *block_size, const int *crops, int data_size)
C 调用示例:
1// 单核(私有存储)示例 2#include <stdio.h> 3 4int main(int argc, char *argv[]) { 5 float *input = (float *)0x10000000; // 输入在 L2 空间 6 float *output = (float *)0x10010000; 7 int input_shape[4] = {400, 2, 2, 3}; 8 int block_size[2] = {2, 2}; 9 int crops[4] = {0, 0, 0, 0}; 10 fp_batchtospace_p(input, output, input_shape, block_size, crops, sizeof(float)); 11 return 0; 12}